/** 摄像机工具 */
export class CameraUtil {
    /**
     * 当前世界坐标是否在摄像机显示范围内
     * @param camera    摄像机
     * @param worldPos  坐标
     */
    static isInView(camera: cc.Camera, worldPos: cc.Vec2 | cc.Vec3) {
        var cameraPos = camera.node.getPosition();
        var viewPos = camera.getWorldToScreenPoint(worldPos);
        //@ts-ignore
        var dir = cc.Vec3.normalize(new cc.Vec3(), worldPos.subtract(cameraPos));
        var forward = camera.node.forward;
        var dot = cc.Vec3.dot(forward, dir);

        const viewportRect = cc.view.getViewportRect();

        // 判断物体是否在相机前面
        if (dot > 0
            // 判断物体是否在视窗内
            && (viewPos.x <= viewportRect.width) && (viewPos.x >= 0)
            && (viewPos.y <= viewportRect.height) && (viewPos.y >= 0))
            return true;
        else
            return false;
    }
}